/*
 * To change this template, choose Tools | Templates and open the template in
 * the editor.
 */
package goodenglish.infrastructure;

import goodenglish.infrastructure.repository.db.DbCreater;
import goodenglish.interfaces.videoplay.PlayMode;

import java.awt.Insets;
import java.awt.Toolkit;
import java.io.File;

import javax.swing.JFrame;

/**
 * 
 * @author 关攀攀 panpan_001@126.com
 */
public class Config {

	// 用户目录
	public static final String USER_HOME_PATH = System.getProperty("user.home");
	public static final String HOME_PATH = USER_HOME_PATH + "/goodEnglish";
	public static final String DB_PATH = HOME_PATH + "/goodenglish.db";
	public static final String PROP_FILE = HOME_PATH + "/GoodEnglish.properties";
	public static final String BACK_PATH = "d:";

	public static String APP_TITLE;

	// 我精通的单词目录
	public static final String WORD_SPLITER = "~@%";
	// 为readline准备的
	public static final String LINE_SPLITER = "@~%";
	// /r/n
	public static final String LINE_SPLITER_REPLACE = "<br/>";
	public static String DICT_PATH;
	public static String DICT_NAME;

	// /n
	public static final String LINE_SPLITER_REPLACE_TWO = "<br>";
	public static final String TIME_SPLITER = "-->";
	public static int SCREEN_WIDTH;
	public static int SCREEN_HEIGHT;
	public static int MENU_HEIGHT = 30;
	public static int HGAP = 10;// 水平间距
	public static int VGAP = 10;// 垂直边距
	/** 播放设置 */
	public static PlayMode PLAY_MODE;
	// 每次学习的字幕数
	public static int PLAYLISTENER_STEP;
	// 字幕学习时间
	public static int PLAYLISTENER_STUDYTIME;
	// 要重播次数
	public static int PLAYLISTENER_REPLAYCOUNT;

	public static int RIGTH_COUNT = 3;

	public static void init() {
		FileUtil.createDire(Config.HOME_PATH);
		File file = new File(Config.PROP_FILE);
		if (!file.exists()) {
			FileUtil.createFileIfNotExsit(Config.PROP_FILE);
			PropUtil.storeProperty("APP_TITLE", "GoodEnglish");
			PropUtil.storeProperty("PLAY_MODE", PlayMode.STUDY_SUBT.toString());
			PropUtil.storePropertyInteger("PLAYLISTENER_STEP", 1);
			PropUtil.storePropertyInteger("PLAYLISTENER_STUDYTIME", 3);
			PropUtil.storePropertyInteger("PLAYLISTENER_REPLAYCOUNT", 1);
			PropUtil.storeProperty("DICT_PATH", "e:/dic");
			PropUtil.storeProperty("DICT_NAME", "langdao-ec-gb");
		}

		Config.APP_TITLE = PropUtil.getProperty("APP_TITLE");
		PLAYLISTENER_STEP = PropUtil.getPropertyInteger("PLAYLISTENER_STEP");
		PLAYLISTENER_STUDYTIME = PropUtil.getPropertyInteger("PLAYLISTENER_STUDYTIME");
		PLAYLISTENER_REPLAYCOUNT = PropUtil.getPropertyInteger("PLAYLISTENER_REPLAYCOUNT");
		String playmode = PropUtil.getProperty("PLAY_MODE");
		if (playmode.equals(PlayMode.STUDY_SUBT.toString())) {
			PLAY_MODE = PlayMode.STUDY_SUBT;
		} else {
			PLAY_MODE = PlayMode.DIRECT;
		}
		DICT_NAME = PropUtil.getProperty("DICT_NAME");
		DICT_PATH = PropUtil.getProperty("DICT_PATH");
		JFrame jFrame = new JFrame();
		Insets insets = Toolkit.getDefaultToolkit().getScreenInsets(jFrame.getGraphicsConfiguration()); // 是指获得屏幕的边界
		Config.SCREEN_WIDTH = Toolkit.getDefaultToolkit().getScreenSize().width;
		Config.SCREEN_HEIGHT = Toolkit.getDefaultToolkit().getScreenSize().height - insets.bottom - 50;
		// 如果数据库不存在 就创建
		File dbFile = new File(DB_PATH);
		if (!dbFile.exists()) {
			DbCreater.reCreateDb();
		}

	}

	public static void alterPLAYLISTENER_STUDYTIME(int studyTime) {
		Config.PLAYLISTENER_STUDYTIME = studyTime;
		PropUtil.storePropertyInteger("PLAYLISTENER_STUDYTIME", Config.PLAYLISTENER_STUDYTIME);
	}

	public static void alterPLAY_MODE(PlayMode playMode) {
		Config.PLAY_MODE = playMode;
		PropUtil.storeProperty("PLAY_MODE", Config.PLAY_MODE.toString());
	}

	public static void alterPLAYLISTENER_STEP(int setp) {
		Config.PLAYLISTENER_STEP = setp;
		PropUtil.storePropertyInteger("PLAYLISTENER_STEP", Config.PLAYLISTENER_STEP);
	}

	public static void alterPLAYLISTENER_REPLAYCOUNT(int count) {
		Config.PLAYLISTENER_REPLAYCOUNT = count;
		PropUtil.storePropertyInteger("PLAYLISTENER_REPLAYCOUNT", Config.PLAYLISTENER_REPLAYCOUNT);
	}
}
